<template>
	<view class="tab">
		<!-- tabNav -->
		<view class="tab-nav">
			<view class="tab-nav-item" @click="tapCard(1)">
				<view class="tab-nav-item-title" :class="active == 1?'tab-nav-item-title-active':''">二手车</view>
				<!-- <view class="tab-nav-item-text">车价透明</view>
				<view class="tab-nav-item-border" :class="active == 1?'tab-nav-item-border-active':''"></view> -->
			</view>
			<!-- <view class="tab-nav-item" @click="tapCard(2)"> -->
				<!-- 	<view class="tab-nav-item" @click="isShowtoast"> -->
			<!-- 	<view class="tab-nav-item-title" :class="active == 2?'tab-nav-item-title-active':''">新车</view>
				<view class="tab-nav-item-text">全网底价</view>
				<view class="tab-nav-item-border" :class="active == 2?'tab-nav-item-border-active':''"></view>
			</view> -->
		</view>
		<!-- tabList -->
		<view class="tab-list">
			<view class="" v-if="active == 1">
				<block v-if="list.length>0">
					<view class="tab-list-li" v-for="(item,index) in list" :key="index">
						<navigator :url="`/pages/carInfo/carInfo?item=${encodeURIComponent(JSON.stringify(item))}`"
							hover-class="none">
							<tab-item :item="item"></tab-item>
						</navigator>
					</view>
					<navigator :url="`/pagesA/buyCar/buyCar`" hover-class="none">
						<view class="looker-more">查看更多<image src="../../static/cxmm.png" mode=""></image></view>
					</navigator>
				</block>
				<view v-else>
					<null></null>
				</view>
			</view>
			<view class="" v-if="active == 2">
				<block v-if="newList.length>0">
					<view class="tab-list-li" v-for="(item,index) in newList" :key="index">
						<navigator :url="`/pagesA/buyCar/newCarDetail?seriesId=${item.seriesId}`" hover-class="none">
							<newcar-tab-item :item="item"></newcar-tab-item>
						</navigator>
					</view>
					<navigator url="/pagesA/buyCar/buyCar?current=1" hover-class="none">
						<view class="looker-more">查看更多<image src="../../static/cxmm.png" mode=""></view>
					</navigator>
				</block>
				<view v-else>
					<null></null>
				</view>
			</view>



		</view>
	</view>
</template>

<script>
	import API from "@/api/index.js"
	export default {
		name: "tab-list",
		props: {
			cityId: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				active: 1,
				list: [],
				newList: [],
			};
		},
		watch: {
			cityId(newVal) {
				this.active = 1
				this.getCarList()
			}
		},
		created() {
			// this.getCarList()
			this.getHomeNewCarList();
		},
		methods: {
			tapCard(index) {
				this.active = index
				// if(index == 1){
				// 	this.getCarList()
				// }else if(index == 2){
				// 	this.getHomeNewCarList()
				// }else if(index == 3){
				// 	this.list = []
				// }
			},
			// 获取车辆列表
			getCarList() {
				const data = {
					page: 1,
					limit: 20,
					cityId: this.cityId
				}
				API.getCarList(data).then(res => {

					// console.log(res.data)
					this.list = res.data
					for (let i=0;i<res.data.length;i++){
						// console.log(res.data[i].carRegistrationTime.substring(0,10))
						this.list[i].carRegistrationTime = res.data[i].carRegistrationTime.substring(0,10)

					}
					
					
					
				})
			},
			// 新车列表
			getHomeNewCarList() {
				const data = {
					page: 1,
					limit: 20,
				}
				API.getHomeNewCarList(data).then(res => {
					this.newList = res.data
				})
			},
			//功能正在开发
			// isShowtoast(){
			// 	uni.showToast({
			// 		title:'功能正在开发中,敬请期待',
			// 		icon:'none'
			// 	})
			// }
		}
	}
</script>

<style scoped lang="scss">
	.tab {
		background-color: $uni-bg-color;
		// margin: $uni-widthspace $uni-widthspace 0rpx;
		border-radius: 10rpx;

		.tab-nav {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.tab-nav-item {
				flex: 1;
				text-align: center;
				padding: $uni-widthspace 0rpx;
				box-sizing: border-box;

				.tab-nav-item-title {
					font-size: 32rpx;
					color: #666;
					font-weight: bolder;
					text-align: left;
					padding-left: 20px;
				}

				.tab-nav-item-title-active {
					color: #333;
				}

				.tab-nav-item-text {
					font-size: 24rpx;
					color: #999;
					margin-top: 8rpx;
				}

				.tab-nav-item-border {
					margin: 0 auto;
					margin-top: 12rpx;
					width: 160rpx;
					height: 6rpx;
					background-color: #fff;
				}

				.tab-nav-item-border-active {
					background-color: #0e2a53;
				}
			}
		}

		.tab-list {
			padding: 0 $uni-widthspace;
			
			.looker-more {
				text-align: center;
				line-height: 120rpx;
				height: 120rpx;
				 width: 190rpx;
				 display: flex;
				margin: auto;
				font-size: 28rpx;
				color: #2C2C2C;
				image{
					width: 10rpx;
					height: 10rpx;
					margin-left: 20rpx;
					margin-top: 54rpx;
					// display: block;
				}
			}

			box-sizing: border-box;

			.tab-list-li {
				border-bottom: 2rpx solid #eee;
				padding: 20rpx 0rpx;
				box-sizing: border-box;
			}
		}
	}
</style>
